<template>
	<view class="page">
		<!-- 搜索框 -->
		<view class="article-search">
			<view class="search">
				<view class="location" @click="getLocation">
					<view class="iconfont icon-dingwei"></view> <!-- 这里可以换成定位图标 -->
				</view>
				<input type="text" placeholder="输入搜索内容" v-model="searchQuery" @confirm="onSearch" />
				<view class="search-button" @click="onSearch">搜索</view>
			</view>

		</view>
		<view class="cart-list">
			<view class="list" v-for="(item, index) in markList" :key="index">
				<view class="check" @click="toggleCheck(index)">
					<text class="iconfont" :class="item.isChecked ? 'icon-checked' : 'icon-check'"></text>
				</view>
				<view class="goods">
					<view class="thumb">
						<image :src="item.logo_img" mode=""></image>
					</view>
					<view class="item">
						<view class="title">
							<view class="two-omit">{{ item.name }}</view>
						</view>
						<view class="title1">
							<view class="two-omit">{{ item.introduce }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>


		<view class="bottom">
			<view class="button" @click="next">
				下一步
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMarkListById
	} from '@/config/api.js';
	export default {
		data() {
			return {
				queryList: {
					navId: null,
					page: 1,
					name: '',
					limit: 20
				},
				markList: [],
				searchQuery: '', // 存储搜索内容
				location: '', // 存储位置信息
				pageTitle: '',
				zhaoshang_id: null,
			};
		},
		// 在目标页面的 onLoad 方法中
		onLoad(options) {
			// 获取传递过来的标题
			const title = decodeURIComponent(options.title);
			if (options.zhaoshang_id) {
				this.zhaoshang_id = options.zhaoshang_id;
				
			}
			// 可以将 title 设置为页面的标题或在页面中使用
			wx.setNavigationBarTitle({
				title: title
			});

			this.pageTitle = title
			this.queryList.navId = options.nav_id;
			this.markListById();
			console.log(options)
			
		},
		methods: {

			markListById() {
				getMarkListById(this.queryList).then(res => {
					res.data.forEach(el => {
						el['isChecked'] = false;
					});
					this.markList = res.data;
				})
			},
			// 获取用户定位
			getLocation() {
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						this.location = `${res.latitude}, ${res.longitude}`; // 存储经纬度
						uni.showToast({
							title: '定位成功',
							icon: 'success',
						});
						console.log('用户定位:', this.location);
					},
					fail: (err) => {
						uni.showToast({
							title: '获取定位失败',
							icon: 'none',
						});
						console.error(err);
					},
				});
			},
			// 执行搜索
			onSearch() {

				this.markListById();
				// if (this.searchQuery.trim()) {
				// 	uni.navigateTo({
				// 		url: `/pages/searchResults/searchResults?query=${encodeURIComponent(this.searchQuery)}`,
				// 	});
				// } else {
				// 	uni.showToast({
				// 		title: '请输入搜索内容',
				// 		icon: 'none',
				// 	});
				// }
			},
			//下一步
			toggleCheck(index) {
				this.markList.forEach(el => {
					el['isChecked'] = false;
				});
				this.markList[index]['isChecked'] = !this.markList[index]['isChecked'];
			},

			next() {
				const title = this.pageTitle;
				console.log('标题:', title);
				const data = this.markList.find(el => el.isChecked);
				let tourl =  `/moduleA/MerchantIn/boWuGuan/settledTable/settledTable?title=${encodeURIComponent(title)}&nav_id=${this.queryList.navId}&store_id=${data.id}`;
				if(this.zhaoshang_id){
					tourl += '&zhaoshang_id='+this.zhaoshang_id
				}
				console.log(tourl,'-----------------------------')
				uni.navigateTo({
					url: tourl
				})
			}
		},
	};
</script>



<style scoped lang="scss">
	@import 'boWuGuan.scss';
</style>